package com.ossjk.oa.accounting.controller;


import java.util.Arrays;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.mapper.Condition;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.ossjk.core.base.controller.BaseController;
import com.ossjk.oa.accounting.entity.CwReceivables;
import com.ossjk.oa.accounting.service.ICwReceivablesService;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author chair
 * @since 2020-05-14
 */
@RestController
@RequestMapping("/accounting/cwReceivables")
public class CwReceivablesController extends BaseController {


	@Autowired
	private ICwReceivablesService iCwReceivablesService;
	
	//@RequiresPermissions("0000")
	@RequestMapping("/list")
	public Object list(Page page) {

	   	Wrapper wrapper = Condition.create();
	   	//  .isWhere(true).orderBy("e.crtm", true);

		page = iCwReceivablesService.selectVoPage(page, wrapper);
		return responseSuccess(page);

	}

	@PostMapping("/insert")
	public Object insert(CwReceivables cw_receivables) {
		Wrapper wrapper = Condition.create();

		if (iCwReceivablesService.insert(cw_receivables)) {
			return responseSuccess();
		} else {
			return responseFail();
		}
	}


	@GetMapping("/toUpdate/{id}")
	public Object toUpdate(@PathVariable("id") String id) {
		return responseSuccess(iCwReceivablesService.selectById(id));
	}

 
	@PutMapping("/update")
	public Object update(CwReceivables cw_receivables) {
		if (iCwReceivablesService.updateById(cw_receivables)) {
			return responseSuccess();
		} else {
			return responseFail();
		}
	}

	@DeleteMapping("/delete/{id}")
	public Object delete(@PathVariable("id") String[] id) {
		if (iCwReceivablesService.deleteBatchIds(Arrays.asList(id))) {
			return responseSuccess();
		} else {
			return responseFail();
		}
	}

 

}

